#include <iostream>
#include <vector>

int n, m, cq, q;
int U[200007], V[200007];
std::vector<int> Q[100007];

int c[200007];
int lft[200007];

std::vector<int> t[400007];
void modify(int p, int l, int r, int ql, int qr, int e) {
  if (ql <= l && r <= qr) {
    t[p].push_back(e);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) {
    modify(p << 1, l, mid, ql, qr, e);
  }
  if (qr > mid) {
    modify(p << 1 | 1, mid + 1, r, ql, qr, e);
  }
}

int to[100007];
int ans[100007];
int fa[200007], sz[200007];
int anc(int u) {
  while (fa[u] != u) {
    u = fa[fa[fa[fa[u]]]];
  }
  return u;
}
int s;

void dfs(int p, int l, int r) {
  int mid = (l + r) >> 1;
  bool conn = (s == 1);
  std::vector<std::pair<int, int>> d;
  if (!conn) {
    d.reserve(t[p].size());
    for (int e : t[p]) {
      int u = anc(U[e]), v = anc(V[e]);
      if (u == v) {
        continue;
      }
      if (sz[u] > sz[v]) {
        std::swap(u, v);
      }
      fa[u] = v, sz[v] += sz[u], --s;
      d.push_back({u, v});
    }
  }
  if (l == r) {
    ans[to[mid]] = s;
  } else {
    dfs(p << 1, l, mid), dfs(p << 1 | 1, mid + 1, r);
  }
  if (!conn) {
    for (int i = int(d.size()) - 1; i >= 0; --i) {
      auto [u, v] = d[i];
      fa[u] = u, sz[v] -= sz[u], ++s;
    }
  }
}

int main() {
  std::freopen("graph.in", "r", stdin);
  std::freopen("graph.out", "w", stdout);
  std::cin.tie(nullptr)->sync_with_stdio(false);
  std::cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    std::cin >> U[i] >> V[i];
  }
  s = n;
  for (int i = 1; i <= n; ++i) {
    fa[i] = i, sz[i] = 1;
  }
  std::cin >> cq;
  for (int i = 1; i <= cq; ++i) {
    int k;
    std::cin >> k;
    if (m - k < n - 1) {
      while (k--) {
        std::cin >> ans[i];
      }
      ans[i] = n;
    } else {
      ++q;
      Q[q].resize(k);
      for (int& j : Q[q]) {
        std::cin >> j;
      }
      to[q] = i;
    }
  }
  if (q == 0) {
    for (int i = 1; i <= cq; ++i) {
      if (ans[i] == 1) {
        std::cout << "YES\n";
      } else {
        std::cout << "NO\n";
      }
    }
    return 0;
  }
  Q[0].reserve(m), Q[q + 1].reserve(m);
  for (int i = 1; i <= m; ++i) {
    c[i] = 1;
    Q[0].push_back(i);
    Q[q + 1].push_back(i);
  }
  for (int i = 1; i <= q + 1; ++i) {
    for (int j : Q[i]) {
      if (!c[j]) {
        modify(1, 1, q, lft[j], i - 1, j);
      }
    }
    for (int j : Q[i - 1]) {
      c[j] = 0;
    }
    for (int j : Q[i]) {
      c[j] = 1;
    }
    for (int j : Q[i - 1]) {
      if (!c[j]) {
        lft[j] = i;
      }
    }
  }
  dfs(1, 1, q);
  for (int i = 1; i <= cq; ++i) {
    if (ans[i] == 1) {
      std::cout << "YES\n";
    } else {
      std::cout << "NO\n";
    }
  }
  return 0;
}